﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Add_Chat.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Add_Chat" %>
<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <%
        string text = Request.QueryString["text"];
        var get_id = new TblChatController().FetchAll().ToList();
        int id = 0;

        if (get_id.Count==0)
            id = 0;
        else
        {
            if (get_id.Count >= 9999)
            {
                foreach (TblChat chat in get_id)
                {
                    new TblChatController().Destroy(chat.ChatId);
                }
            }
            else
            {
                var get_id_last = new TblChatController().FetchAll().Last();
                id = get_id_last.ChatId;

                id++;
            }
        }

        new TblChatController().Insert(id, text, DateTime.Now, int.Parse(Session["admin_id"].ToString()));
        %>
</body>
</html>
